perm filename DEVINS.FAI[S,HE] blob sn#498964 filedate 1982-04-13 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		TITLE	PIXSUB
C00003 00003	ADDIEL:	POP	P,RETAD      like ADDEL, but interpolates
C00008 ENDMK
C⊗;
	TITLE	PIXSUB
	ENTRY	ADDIEL
	I←1
	J←2
	K←3
	II←T←4
	JJ←M←5
	AR←6
	A←7
	B←10
	C←11

	D←13
        V←14
	P←17

PCLN←←0
PCWD←←1
PCBY←←2
PCBYA←←3
LNWD←←4
LNBY←←5
LNBYA←←6
WDBY←←7
WDBI←←10
BYBI←←11
BMAX←←12
BPTAB←13
LINTAB←←14

RETAD:	0
;ADDIEL:	POP	P,RETAD     ; like ADDEL, but interpolates
; V holds "brightness", floating point.
; I holds y-position in pixels, floating point.
; J holds x-position in pixels, floating point.
; AR holds picture address.
ADDIEL:	POP	P,RETAD     ; like ADDEL, but interpolates
	POP	P,V
	POP	P,J	    ; I, J and value are floating point
	POP	P,I		; NO BOUNDS CHECKING...I,J must be inside picture
	POP	P,AR
	KIFIX	II,I		; KIFIX truncates, not rounds.
	KIFIX	JJ,J

	MOVEI	K,LINTAB(AR)	; Make a byte pointer to the upper left of
	HRRM	K,LNTBP		;  the four pixels that will be modified.
	MOVE	K,BPTAB(AR)
	HRRM	K,BPTBP
LNTBP:	MOVE	K,LINTAB(II)
BPTBP:	ADD	K,BPTAB(JJ)
	FLTR	II,II
	FLTR	JJ,JJ
	FSBR	I,II		; I gets fractional part of y-value, and
	FSBR	J,JJ		; J gets fractional part of x-value

; What happens next is that the accumulators A, B, C, and D are set up so that
;  they contain the integers to be added to the four-pixel block pointed to by
;  K, in the following configuration:
;			K-->A B
;			    C D
;  in other words, K points to the byte which must be incremented by the contents
;  of A and so on.

	MOVE	B,J		; This is all H. P. Magic
	MOVE	C,I
	MOVE	D,I	; Everything makes sense when you use the following rule:
	FMPR	D,J	;  The portion of the "brightness" that a pixel gets is
	FSBR	B,D	;  equal to (1 - its x-distance from the point) times (1 - 
	FSBR	C,D	;  its y-distance from the point).  Here, I is the y-dist-
			;  ance from A, and J is the x-distance from A, so the
	FIXR	A,V	;  portions of V are:
			;    A = (1-I)(1-J) = 1-I-J-IJ
	FMPR	B,V	;    B = (1-I)J = J-IJ
	FMPR	C,V	;    C = (1-J)I = I-IJ
	FMPR	D,V	;    D = IJ
	FIXR	B,B	;  So this is implemented by taking D=IJ, C=I-D, B=J-D,
	FIXR	C,C	;  and A=1-B-C-D, and multiplying them all by V then
	FIXR	D,D	;  rounding them off to integral values.

	SUB	A,B
	SUB	A,C
	SUB	A,D		; End of magical incantations

	LDB	T,K			; Now do the updating...K points to "A"
	ADD	T,A
	CAIGE	T,0			; Don't store a negative
	MOVEI	T,0
	CAMLE	T,BMAX(AR)		;  or too big a value
	MOVE	T,BMAX(AR)
	DPB	T,K

	ADD	K,LNWD(AR)		; "C" is on the next line, LNWD words away
	LDB	T,K
	ADD	T,C
	CAIGE	T,0
	MOVEI	T,0
	CAMLE	T,BMAX(AR)
	MOVE	T,BMAX(AR)
	DPB	T,K

	ILDB	T,K			; Increment the pointer to get to "D"
	ADD	T,D
	CAIGE	T,0
	MOVEI	T,0
	CAMLE	T,BMAX(AR)
	MOVE	T,BMAX(AR)
	DPB	T,K

	SUB	K,LNWD(AR)		; "B" is on the previous line
	LDB	T,K
	ADD	T,B
	CAIGE	T,0
	MOVEI	T,0
	CAMLE	T,BMAX(AR)
	MOVE	T,BMAX(AR)
	DPB	T,K

	JRST	@RETAD

	END